﻿namespace Pottery.Model.Infrastructure.Models
{
    using System;
    using System.Data.Services.Common;
    using System.Data.SqlTypes;
    using System.Runtime.Serialization;
    using Model.Infrastructure;

    /// <summary>
    /// Agreement
    /// </summary>
    [DataContract]
    [DataServiceEntity]
    public class Agreement : IValidatable, IAssignable, INullable
    {

        public Agreement()
        {

        }

        #region Properties
        /// <summary>
        /// Link to the picture from the customer for Individual order
        /// </summary>
        [DataMember]
        public string PictureLink
        {
            get { return mPictureLink; }
            set
            {
                if (!IsNull)
                    mPictureLink = value;
            }
        }

        /// <summary>
        /// Is it Possible to produce this product
        /// </summary>
        [DataMember]
        public bool IsPossible
        {
            get { return mIsPossible; }
            set
            {
                if (!IsNull)
                    mIsPossible = value;
            }
        }

        /// <summary>
        /// Time For Produce
        /// </summary>
        [DataMember]
        public DateTime TimeForProduce
        {
            get { return mTimeForProduce; }
            set
            {
                if (!IsNull)
                    mTimeForProduce = value;
            }
        }

        /// <summary>
        /// Product In Agreement
        /// </summary>
        [DataMember]
        public Product ProductInAgreement
        {
            get { return mProductInAgreement; }
            set
            {
                if (!IsNull)
                    mProductInAgreement = value;
            }
        }

        /// <summary>
        /// Agreement Number
        /// </summary>
        [DataMember]
        public int AgreementNumber
        {
            get { return mAgreementNumber; }
            set
            {
                if (!IsNull)
                    mAgreementNumber = value;
            }
        }

        /// <summary>
        /// Date Of Agreement
        /// </summary>
        [DataMember]
        public DateTime DateOfAgreement
        {
            get { return mDateOfAgreement; }
            set
            {
                if (!IsNull)
                    mDateOfAgreement = value;
            }
        }
        #endregion

        #region IValidatable implementation
        /// <summary>
        /// Checks instance for data`s validity
        /// </summary>
        /// <returns>checking result</returns>
        public bool Validate()
        {
            return true;
        }
        #endregion

        #region IAssignable implementation

        /// <summary>
        /// Copy data from current object to object in param.
        /// </summary>
        /// <param name="obj">object to change </param>
        public void AssignTo(object obj)
        {
            if (IsNull)
                throw new InvalidOperationException();

            if (obj == null)
                throw new ArgumentNullException("obj");

            if (obj is Agreement)
            {
                Agreement agr = obj as Agreement;

                agr.mAgreementNumber = mAgreementNumber;
                agr.mDateOfAgreement = mDateOfAgreement;
                agr.mIsPossible = mIsPossible;
                agr.mPictureLink = mPictureLink;
                agr.mProductInAgreement = mProductInAgreement;
                agr.mTimeForProduce = mTimeForProduce;

                agr.mNull = false;

                return;
            }

            throw new NotSupportedException("Not supported type!");
        }

        #endregion

        #region INullable Implementation

        public bool IsNull
        {
            get { return mNull; }
        }

        public static Agreement Null
        {
            get
            {
                Agreement agr = new Agreement();
                agr.mNull = true;
                return agr;
            }
        }

        #endregion

        #region private Fields
        private string mPictureLink;
        private bool mIsPossible;
        private DateTime mTimeForProduce;
        private Product mProductInAgreement;
        private int mAgreementNumber;
        private DateTime mDateOfAgreement;
        private bool mNull = false;
        #endregion
    }
}
